﻿//-------------
// <copyright file="DomainMapper.cs" company="Uncas">
//     Copyright (c) Ole Lynge Sørensen. All rights reserved.
// </copyright>
//-------------

namespace Uncas.Katas.SimpleMembership.Domain
{
    using System.Collections.Generic;
    using System.Web.Security;
    using AutoMapper;

    /// <summary>
    /// Maps to domain objects.
    /// </summary>
    public static class DomainMapper
    {
        /// <summary>
        /// Configures this instance.
        /// </summary>
        public static void Configure()
        {
            Mapper.CreateMap<MembershipUser, User>();
        }

        /// <summary>
        /// Maps the membership user to domain.
        /// </summary>
        /// <param name="mu">The membership user.</param>
        /// <param name="roles">The roles.</param>
        /// <returns>The domain user.</returns>
        public static User MapMembershipUserToDomain(
            MembershipUser mu, 
            IEnumerable<string> roles)
        {
            var user = Mapper.Map<MembershipUser, User>(mu);
            user.Roles = roles;
            return user;
        }
    }
}